Google News
logo
jQuery - Interview Questions
What is the difference between width() vs css(‘width’) in jQuery?
CSS(‘width’) returns the width value in pixels, whereas width() returns the integer (without the unit values). For example:
 
div{
width: 20cm;
}
If you print the values:
 
$(this).width();
$(this).css(‘width’);
 
you will get the values like 756 and 756px respectively. Note that though we specified width in cm, it is converted to pixel (px) for output purposes.
Advertisement